def shi():
    print("举头望明月，低头思故乡！") #声明函数

shi() #调用函数

def add():
    a = 3
    b = 5
    s = a + b
    print(s)
    return a #只是有返回值，没有显示

c = add()
print(c)

def add(a, b):
    print(a + b)
#实参为常量
add(1 , 3)
#实参为变量
a = 1
b = 3
add(a , b)
#实参为常量，变量，表达式和组合
add(2 * 3, 4 * 5)

c = 3
add(8, c * 3)

def score(a, b, c):
    print("张三的成绩为：",a)
    print("李四的成绩为：", b)
    print("王五的成绩为：", c)

score(85, 65, 89)
score(b=65, a=85, c=89)

def reg(name, age, sex="女"):
    print("姓名：{}年龄：{}性别：{}".format(name, age, sex))

reg("张三",20)
reg("李四",21,"男")

def favfruits(*fruits):
    print("我最喜欢的水果：")
    for i in fruits:
        print(i)


favfruits("苹果", "香蕉")
favfruits("草莓")


def show(a, b, *l):
    print(a)
    print(b)
    print(l)


show(1, 2, 3, 4, 5, 99)

def re(a, b, c, d):
    return a+b, c*d, a-c

ss=re(1,2,3,4)
print(ss)

#局部变量和全局变量
def fun():
    a = 20
    return a

a = 10
print(a)
print(fun())
#递归函数计算阶乘
def f(n):
    if n <= 1:
        return 1
    else:
        return n*f(n-1)

num = int(input("请输入一个正整数："))
s = f(num)
print(num,"的阶乘是", s)
#利用递归计算1~100
def sum(n):
    if n == 1:
        return 1
    else:
        return n+sum(n-1)

print("1~100相加的和为",sum(100))
#计算斐波那契数列
def fibo(n):
    if n <= 2:
        return 1
    else:
        return fibo(n - 1) + fibo(n - 2)

print("斐波那契数列的第{}项为{}".format(7,fibo(7)))
#匿名函数
sum = lambda a, b, c: a+b+c
print(sum(1, 2, 3))

fum =  lambda m: m**2
print(fum(5))